package com.ojoin.trade.common.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.ojoin.trade.common.utils.CommonUtils;
import com.ojoin.trade.common.web.domain.Notification;
import com.ojoin.trade.common.web.domain.Result;
import com.ojoin.trade.common.web.service.impl.NotificationService;

@Controller
@RequestMapping(value = "/notification")
public class NotificationController extends SimpleBaseController  {
 

	@Autowired
    private NotificationService notificationDataService;
 
 
	@ResponseStatus(HttpStatus.OK)
    @RequestMapping(value ="list", method = RequestMethod.GET,consumes=MediaType.APPLICATION_FORM_URLENCODED_VALUE,produces=MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Result list(Notification dict, Pageable page) {
    	dict.setUserId(CommonUtils.getLoginUserId());
    	return new Result(Result.Status.OK,notificationDataService.queryList(dict, page));
    }
    
    @RequestMapping(value ="markReadAll", method = RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Result markRead() {
        notificationDataService.markReadAll(CommonUtils.getLoginUserId());
        return new Result(Result.Status.OK, "操作成功");
    }

    @RequestMapping(value ="/{id}/markRead", method = RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Result markRead(@PathVariable("id") Integer id) {
        notificationDataService.markRead(id);
        return new Result(Result.Status.OK, "操作成功");
    }

}
